﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LeanEngine.Configuration;

namespace LeanEngine.Data.Linq.Builder
{
    internal sealed class PagedQueryBuilder : IPagedQueryBuilder
    {
        #region Declaration Members

        private IPagedQueryBuilder _pagedQueryBuilder;

        #endregion
        
        #region Constructor Members

        public PagedQueryBuilder()
        {
            var defaultConnection = AppSetting.GetConnection("defaultConnection");
            this._pagedQueryBuilder = (defaultConnection.ProviderName == "System.Data.SqlClient")
                ? new SqlClient.PagedQueryBuilder()
                : PluginProvider.LoadInterface<IPagedQueryBuilder>();
        }

        #endregion

        #region IPagedQueryBuilder Members

        public int PageIndex
        {
            get { return this._pagedQueryBuilder.PageIndex; }
            set { this._pagedQueryBuilder.PageIndex = value; }
        }

        public int PageSize
        {
            get { return this._pagedQueryBuilder.PageSize; }
            set { this._pagedQueryBuilder.PageSize = value; }
        }

        #endregion

        #region IQueryBuilder Members

        public string BuildTSQL(LinqQuery linqQuery)
        {
            return this._pagedQueryBuilder.BuildTSQL(linqQuery);
        }

        #endregion
    }
}
